<?php
/**
 * 
 * 根据话题抓取微博数据
 * @author yangchao
 * @since 2012-03-19
 */

if (!file_exists("../SINASRV_CONFIG")) {
	echo "Read the sinasrv config error!\n";
//	exit();
} else {
   $array_config = parse_ini_file("../SINASRV_CONFIG", true); $_SERVER = array_merge($_SERVER, $array_config); 
}

/*ini_set("display_errors",ture);
error_reporting(E_ALL);*/

define("CRON_NAME","cron_update_tuijian");//cro名称，要求唯一
set_time_limit(0);
$_GET["db_debug"] = true;
$_GET["no_pref_debug"] = true;
//$_GET["api_debug"] = true;

//15分钟一次,执行1000条
define("PCOUNT",10);//每次处理多少mid
define("MAX_PAGE",1000); //定义每个进程处理最大的页数
define("TOTAL_PROCESS",1);//添加新进程需要更新这个配置
define("NOW_PROCESS",$argv[1] ? $argv[1] : 0);//当前进程ID=0 可以申请如下php xxx 1
define("CRON_START_TIME",time());

include_once($_SERVER['DOCUMENT_ROOT'] ."/include/user/inc.php");
include_once($_SERVER['DOCUMENT_ROOT'] ."/include/tucao/inc.php");
include_once($_SERVER['DOCUMENT_ROOT'] ."/include/mblog/inc.php");
include_once($_SERVER['DOCUMENT_ROOT'] ."/include/tuijian/inc.php");
include_once($_SERVER['DOCUMENT_ROOT'] ."/include/album/inc.php");
class mod_cron_engine_main extends mod_cron_engine
{
	function __construct($current_process_id)
	{
		parent::__construct($current_process_id,CRON_NAME);
	}
	
	
	function craw()
	{
		$this->get_data();
	}
	
	
	function  run()
	{
		//开始跑cron之前预先获取数据（start_id等）
		$this->before_run();
		
		//正式获取数据
		$this->craw();
		
		
		$this->after_run();
	}
	
	
	function get_data()
	{
		$res = $this->replace_into_data(0);	
		
		$this->update_daren();
		$this->update_alnum();
		$this->update_mblog();
		
		$res = $this->replace_into_data(1);	
	}	
	
	function update_daren()
	{
		$db_user_info = new db_user_info();
		$user_list = $db_user_info->get_user_order_by_count_tuijian_nocache(1,20);
			
		$db_tuijian_daren = new db_tuijian_daren();
		
		$db_tuijian_daren->cron_del_tuijian_daren();
		
		
		foreach($user_list as $key=> $value)
		{
			$db_tuijian_daren->cron_insert_tuijian_daren($value["uid"],$key,serialize($value));
			
		}
	}
	
	
	
	function update_alnum()
	{
		
		$db_album_info = new db_album_info();
		$album_list = $db_album_info->get_user_order_by_count_tuijian_nocache(1,10);
			
		$db_tuijian_album = new db_tuijian_album();
		
		$db_tuijian_album->cron_del_tuijian_album();
		
		
		foreach($album_list as $key=> $value)
		{
			$db_tuijian_album->cron_insert_tuijian_album($value["id"],$key,$value["create_uid"],serialize($value));
			
		}
		
	}
	
	
	function update_mblog()
	{
		
		$db_album_info = new db_mblog_pic_content();
		$db_tuijian_mblog = new db_tuijian_mblog();
		$db_tuijian_mblog->cron_del_tuijian_mblog();
			
		for($i = 1 ;$i <= 4 ; $i ++)
		{
			$mblog_list = $db_album_info->get_user_order_by_count_tuijian_nocache($i,1,10);
				
			
			foreach($mblog_list as $key=> $value)
			{
				$db_tuijian_mblog->cron_insert_tuijian_mblog($i,$value["id"],$key,$value["create_uid"],serialize($value));
				
			}
		}
			
		
		
	}
}

$m = new mod_cron_engine_main(NOW_PROCESS);
$m->run();
